/**
 * 剑指 Offer 45. 把数组排成最小的数
 * https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
 */

/**
 * @param {number[]} nums
 * @return {string}
 */
function minNumber(nums) {
  const numsStr = new Array(nums.length);
  for (let i = 0; i < nums.length; i += 1) {
    numsStr[i] = String(nums[i]);
  }
  numsStr.sort((a, b) => (a + b > b + a ? 1 : -1));
  return numsStr.join('');
}

console.log(minNumber([10, 2]) === '102');
console.log(minNumber([3, 30, 34, 5, 9]) === '3033459');
